package com.hooper.login.handler;

import com.hooper.login.entity.Result;
import com.hooper.login.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author Tim Hooper
 * @version 1.0
 * @time 2022/12/28/12:53
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public Result businessException(BusinessException businessException) {
        log.info("异常原因：" + businessException.getMessage());
        return Result.fail(businessException.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e) {
        log.info("处理异常" + e.getCause());
        e.printStackTrace();
        return Result.fail(e.getMessage());
    }


}
